package com.base.common.exception;

import com.base.common.result.ResultCode;


/**
 * @author zhou minghao
 * @date 2024/4/23
 * @description
 */
public class GlobalException extends RuntimeException{
    /**
     * 错误码，用于全局异常拦截器使用
     */
    private final Integer code;

    public GlobalException(String message) {
        super(message);
        this.code = 500;
    }

    public GlobalException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public GlobalException(String message, Throwable cause) {
        super(message, cause);
        this.code = 500;
    }

    public GlobalException(Throwable cause) {
        super(cause);
        this.code = 500;
    }

    public GlobalException(ResultCode resultCode) {
        super(resultCode.getMsg());
        this.code = resultCode.getCode();
    }

    public Integer getCode() {
        return code;
    }
}
